from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-09 14:07:08.332417
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 09, Aug, 2022
Time: 14:07:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.0750
Nobs: 743.000 HQIC: -50.4182
Log likelihood: 9411.92 FPE: 1.02363e-22
AIC: -50.6335 Det(Omega_mle): 9.07584e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296154 0.055582 5.328 0.000
L1.Burgenland 0.107812 0.036848 2.926 0.003
L1.Kärnten -0.106562 0.019526 -5.457 0.000
L1.Niederösterreich 0.207194 0.076839 2.696 0.007
L1.Oberösterreich 0.108899 0.075029 1.451 0.147
L1.Salzburg 0.255080 0.039354 6.482 0.000
L1.Steiermark 0.041252 0.051375 0.803 0.422
L1.Tirol 0.108088 0.041676 2.594 0.009
L1.Vorarlberg -0.062586 0.035836 -1.746 0.081
L1.Wien 0.049559 0.066406 0.746 0.455
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057896 0.116084 0.499 0.618
L1.Burgenland -0.032082 0.076958 -0.417 0.677
L1.Kärnten 0.047028 0.040781 1.153 0.249
L1.Niederösterreich -0.175759 0.160480 -1.095 0.273
L1.Oberösterreich 0.408099 0.156699 2.604 0.009
L1.Salzburg 0.287840 0.082191 3.502 0.000
L1.Steiermark 0.107720 0.107297 1.004 0.315
L1.Tirol 0.311257 0.087041 3.576 0.000
L1.Vorarlberg 0.025171 0.074844 0.336 0.737
L1.Wien -0.029783 0.138691 -0.215 0.830
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189139 0.028520 6.632 0.000
L1.Burgenland 0.090280 0.018908 4.775 0.000
L1.Kärnten -0.008813 0.010019 -0.880 0.379
L1.Niederösterreich 0.260583 0.039428 6.609 0.000
L1.Oberösterreich 0.137885 0.038499 3.582 0.000
L1.Salzburg 0.045638 0.020193 2.260 0.024
L1.Steiermark 0.021087 0.026362 0.800 0.424
L1.Tirol 0.093288 0.021385 4.362 0.000
L1.Vorarlberg 0.055595 0.018388 3.023 0.002
L1.Wien 0.116488 0.034075 3.419 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107465 0.028993 3.707 0.000
L1.Burgenland 0.045893 0.019221 2.388 0.017
L1.Kärnten -0.013787 0.010186 -1.354 0.176
L1.Niederösterreich 0.189502 0.040082 4.728 0.000
L1.Oberösterreich 0.301789 0.039137 7.711 0.000
L1.Salzburg 0.110046 0.020528 5.361 0.000
L1.Steiermark 0.103670 0.026799 3.868 0.000
L1.Tirol 0.105590 0.021739 4.857 0.000
L1.Vorarlberg 0.068781 0.018693 3.679 0.000
L1.Wien -0.019801 0.034640 -0.572 0.568
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126122 0.052782 2.390 0.017
L1.Burgenland -0.050065 0.034991 -1.431 0.152
L1.Kärnten -0.040604 0.018542 -2.190 0.029
L1.Niederösterreich 0.170919 0.072968 2.342 0.019
L1.Oberösterreich 0.138376 0.071248 1.942 0.052
L1.Salzburg 0.288906 0.037371 7.731 0.000
L1.Steiermark 0.035458 0.048786 0.727 0.467
L1.Tirol 0.163123 0.039576 4.122 0.000
L1.Vorarlberg 0.100840 0.034030 2.963 0.003
L1.Wien 0.068965 0.063060 1.094 0.274
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056321 0.041954 1.342 0.179
L1.Burgenland 0.039558 0.027813 1.422 0.155
L1.Kärnten 0.051225 0.014739 3.476 0.001
L1.Niederösterreich 0.218626 0.057999 3.769 0.000
L1.Oberösterreich 0.294480 0.056632 5.200 0.000
L1.Salzburg 0.043892 0.029704 1.478 0.140
L1.Steiermark 0.000279 0.038778 0.007 0.994
L1.Tirol 0.143419 0.031457 4.559 0.000
L1.Vorarlberg 0.072245 0.027049 2.671 0.008
L1.Wien 0.080824 0.050124 1.612 0.107
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173926 0.050148 3.468 0.001
L1.Burgenland -0.002335 0.033245 -0.070 0.944
L1.Kärnten -0.062443 0.017617 -3.544 0.000
L1.Niederösterreich -0.077254 0.069327 -1.114 0.265
L1.Oberösterreich 0.188600 0.067693 2.786 0.005
L1.Salzburg 0.058339 0.035506 1.643 0.100
L1.Steiermark 0.234277 0.046352 5.054 0.000
L1.Tirol 0.498620 0.037601 13.261 0.000
L1.Vorarlberg 0.045108 0.032332 1.395 0.163
L1.Wien -0.054526 0.059914 -0.910 0.363
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158855 0.057966 2.741 0.006
L1.Burgenland -0.007969 0.038428 -0.207 0.836
L1.Kärnten 0.066347 0.020364 3.258 0.001
L1.Niederösterreich 0.205696 0.080135 2.567 0.010
L1.Oberösterreich -0.068537 0.078246 -0.876 0.381
L1.Salzburg 0.210679 0.041041 5.133 0.000
L1.Steiermark 0.120655 0.053578 2.252 0.024
L1.Tirol 0.072318 0.043463 1.664 0.096
L1.Vorarlberg 0.119746 0.037373 3.204 0.001
L1.Wien 0.123467 0.069254 1.783 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358688 0.033243 10.790 0.000
L1.Burgenland 0.007193 0.022038 0.326 0.744
L1.Kärnten -0.023477 0.011678 -2.010 0.044
L1.Niederösterreich 0.215107 0.045956 4.681 0.000
L1.Oberösterreich 0.199492 0.044873 4.446 0.000
L1.Salzburg 0.044349 0.023537 1.884 0.060
L1.Steiermark -0.013718 0.030726 -0.446 0.655
L1.Tirol 0.104375 0.024926 4.187 0.000
L1.Vorarlberg 0.070653 0.021433 3.296 0.001
L1.Wien 0.039236 0.039716 0.988 0.323
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039496 0.139440 0.192291 0.151262 0.117641 0.103357 0.065558 0.217843
Kärnten 0.039496 1.000000 -0.007517 0.132051 0.039385 0.094025 0.432854 -0.053722 0.097375
Niederösterreich 0.139440 -0.007517 1.000000 0.333628 0.141904 0.293112 0.096383 0.179905 0.312619
Oberösterreich 0.192291 0.132051 0.333628 1.000000 0.228431 0.325566 0.176343 0.167892 0.261669
Salzburg 0.151262 0.039385 0.141904 0.228431 1.000000 0.142571 0.112879 0.145432 0.124281
Steiermark 0.117641 0.094025 0.293112 0.325566 0.142571 1.000000 0.146591 0.137662 0.071183
Tirol 0.103357 0.432854 0.096383 0.176343 0.112879 0.146591 1.000000 0.112948 0.142965
Vorarlberg 0.065558 -0.053722 0.179905 0.167892 0.145432 0.137662 0.112948 1.000000 0.002678
Wien 0.217843 0.097375 0.312619 0.261669 0.124281 0.071183 0.142965 0.002678 1.000000